/**
 * Created by wolfMan on 2025/07/01.
 */
import Vue from 'vue';
import { Foundation } from './index';

export default {
  data () {
    return {
    };
  },
  methods: {
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {搜索重置}
    */
    resetQuery () {
      this.resetForm('searchForm');
      this.search();
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {改变页面表格宽度}
    */
    changeColumnWidth (_newWidth, _oldWidth, _column) {
      // 表格宽度改变
      if (this.$refs['rightToolbar'] && _newWidth !== _oldWidth) {
        this.$refs['rightToolbar'].changeColumnWidth(_column);
      };
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {对象属性过滤}
    */
    MixinFilterParams (_params) {
      let params = {};
      for (let item in _params) {
        if (this.isExist(_params[item])) {
          if (Object.prototype.toString.call(_params[item]) !== '[object Array]' || !_params[item].length) {
            params[item] = _params[item];
          };
        };
      };
      return params;
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {单个参数过滤}
    */
    isExist (str) {
      if (str !== '' && str !== undefined && str !== null) {
        return true;
      };
      return false;
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {返回克隆后的对象}
    */
    MixinClone (obj) {
      return JSON.parse(JSON.stringify(obj));
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {用于修改单条表格数据后，set到tableData中}
    */
    MixinSetTableData (tableData, idName, id, response) {
      const { data } = tableData;
      const index = data.findIndex(item => item[idName] === id);
      Vue.set(data, index, response);
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {用于判断表单是否为空}
    */
    MixinRequired (message, trigger) {
      return {
        required: true, pattern: /^\S.*$/gi, message: message, trigger: trigger || 'blur'
      };
    },
    /**
      * @date2025/07/01
      * @author wolfMan
      * @description {表格格式化金钱}
    */
    MixinFormatPrice (cellValue) {
      if (typeof cellValue !== 'number') {
        return '';
      }
      return '￥' + Foundation.formatPrice(cellValue);
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {表格格式化金钱}
    */
    MixinTableFormatPrice (row, column, cellValue) {
      if (typeof cellValue !== 'number') {
        return '';
      }
      return '￥' + Foundation.formatPrice(cellValue);
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {表格格式化时间戳}
    */
    MixinUnixToDate (row, column, cellValue) {
      return Foundation.unixToDate(cellValue);
    },
    /**
      * @date 2025/07/01
      * @author wolfMan
      * @description {分页}
    */
    pageChange (pageVal) {
      if (pageVal[0] === 1) {
        this.pageIndex = pageVal[1];
      } else if (pageVal[0] === 2) {
        this.pageSize = pageVal[1];
      }
      this.search('selectPage');
    }
  },
  activated () {
    // 进入页面时若存在tooltip,设置其隐藏
    const nodeList = document.querySelectorAll('.el-tooltip__popper');
    nodeList.forEach(item => {
      item.style.display = 'none';
    });
  }
};